﻿using System;
using System.IO;
using System.Windows.Forms;

namespace WindowsFormsApp1 {
    public partial class Form1 : Form {
        public Form1() {
            InitializeComponent();
        }

        private void button2_Click(object sender, EventArgs e) {
            try {
                OpenFileDialog openFileDialog = new OpenFileDialog();
                openFileDialog.Multiselect = true;
                openFileDialog.Title = "请选择文件";
                openFileDialog.Filter = "文本文件(*.txt)|*.txt";
                openFileDialog.InitialDirectory = Directory.GetCurrentDirectory() + "\\txt";
                string file = "";
                if (openFileDialog.ShowDialog() == DialogResult.OK) {
                    file = openFileDialog.FileName;
                }

                this.label2.Text = file;
            }
            catch (Exception exception) {
                this.label3.Text = "出错！";
                throw;
            }
        }

        private void button3_Click(object sender, EventArgs e) {
            try {
                string data = Directory.GetCurrentDirectory() + "\\Data";
                string file1 = this.label1.Text;
                string file2 = this.label2.Text;
                if (file1 == ""||file2=="") {
                    this.label3.Text = "请先选择文件！";
                    return;
                }
                if (!Directory.Exists(data)) Directory.CreateDirectory(data);//如果Data目录不存在则创建
                if(File.Exists(data+"\\new.txt"))File.Delete(data+"\\new.txt");//如果新文件存在则删除
                File.AppendAllText(data+"\\new.txt",File.ReadAllText(file1));
                File.AppendAllText(data+"\\new.txt",File.ReadAllText(file2));
                this.label3.Text = "合并成功！";
            }
            catch (Exception Exception) {
                this.label3.Text = "出错！";
                throw;
            }
        }

        private void button1_Click(object sender, EventArgs e) {
            try {
                OpenFileDialog openFileDialog = new OpenFileDialog();
                openFileDialog.Multiselect = true;
                openFileDialog.Title = "请选择文件";
                openFileDialog.Filter = "文本文件(*.txt)|*.txt";
                openFileDialog.InitialDirectory = Directory.GetCurrentDirectory() + "\\txt";
                string file = "";
                if (openFileDialog.ShowDialog() == DialogResult.OK) {
                    file = openFileDialog.FileName;
                }

                this.label1.Text = file;
            }
            catch (Exception exception) {
                this.label3.Text = "出错！";
                throw;
            }
        }

        private void label1_Click(object sender, EventArgs e) {
            throw new System.NotImplementedException();
        }

        private void label3_Click(object sender, EventArgs e) {
            throw new System.NotImplementedException();
        }
    }
}